package com.homwee.listMenu.util;

import java.io.File;
import java.util.List;
import java.util.Map;

import com.homwee.factory.R;

import android.content.Context;
import android.graphics.Color;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

public class ExtraAdapter extends BaseAdapter{
	private List<? extends Map<String, ?>> data;
	private Context mContext;
	private int flag =0;
	//flag =0 extraActivity cloumn12
	//flag =1 extraActivity cloumn3 
	//flag =2 dataIndex show
	
	public ExtraAdapter(List<? extends Map<String, ?>> data,Context context,int flag){
		this.data=data;
		this.mContext=context;
		this.flag=flag;
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return data.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return data.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public View getView(int position, View view, ViewGroup parent) {
		// TODO Auto-generated method stub
		if(view==null){
			view=LayoutInflater.from(mContext).inflate(R.layout.simple_list_item, parent,false);
		}
		TextView name=view.findViewById(R.id.info_name);
		TextView values=view.findViewById(R.id.info_values);
		
		name.setText((String) data.get(position).get("names"));
		values.setText((String)data.get(position).get("values"));
		
		if(flag==1){
			LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) values.getLayoutParams();
			values.getLayoutParams();

			params.weight = 2.5f;
		}
		
		String str=(String)data.get(position).get("values");
		Log.d("tag","++"+str+"++"+String.valueOf(data.get(position).get("names")));
		if(str.equals("OK")){
			name.setTextColor(Color.parseColor("#32CD32"));
			values.setTextColor(Color.parseColor("#32CD32"));
		}
		else if(str.equals("NG")){
			name.setTextColor(Color.parseColor("#FF0000"));
			values.setTextColor(Color.parseColor("#FF0000"));
		}

		if(flag==2){
			File tempFile=new File(str);
			if(tempFile.exists()){
				//name.setTextColor(Color.parseColor("#32CD32"));
				values.setTextColor(Color.parseColor("#32CD32"));
			}else{
				//name.setTextColor(Color.parseColor("#FF0000"));
				values.setTextColor(Color.parseColor("#FF0000"));
			}
		}

		return view;
	}

}
